// pages/orderdetails/orderdetails.js
var app = getApp();
var c = require('../common.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showPayPwdInput: false, //是否展示密码输入层
    pwdVal: '', //输入的密码
    payFocus: true, //文本框焦点
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var order_id = options.order_id;
    var user_id = app.u.user_id;
    var that = this;
    var filePath = app.filePath;
    this.setData({
      filePath: filePath,
      order_id: order_id
    })
    c.ajax(
      app.url + 'orderdetails', {
        order_id: order_id,
        user_id: user_id
      },
      res => {
        console.log(res);
        that.setData({
          data: res.data
        })
      }
    )
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  jujue: function(e) {
    var teacherid = e.currentTarget.dataset.tid;
    var order_id = this.data.order_id;
    var user_id = app.u.user_id;
    var that = this;
    c.ajax(
      app.url + 'jujue', {
        teacherid: teacherid,
        order_id: order_id,
        user_id: user_id
      },
      res => {
        console.log(res);
        that.setData({
          data: res.data
        })
      }
    )
  },
  select: function(e) {
    var teacherid = e.currentTarget.dataset.tid;
    this.setData({ teacherid: teacherid});
    this.showInputLayer();
  },
  /**
   * 显示支付密码输入层
   */
  showInputLayer: function() {
    this.setData({
      showPayPwdInput: true,
      payFocus: true
    });
  },
  /**
   * 隐藏支付密码输入层
   */
  hidePayLayer: function() {

    var val = this.data.pwdVal;

    this.setData({
      showPayPwdInput: false,
      payFocus: false,
      pwdVal: ''
    }, function() {
      wx.showToast({
        title: val,
      })
    });

  },
  /**
   * 获取焦点
   */
  getFocus: function() {
    this.setData({
      payFocus: true
    });
  },
  /**
   * 输入密码监听
   */
  inputPwd: function(e) {
    this.setData({
      pwdVal: e.detail.value
    });

    if (e.detail.value.length >= 6) {
      this.hidePayLayer();
    }
  },


  /**
   * 显示支付密码输入层
   */
  showInputLayer: function() {
    this.setData({
      showPayPwdInput: true,
      payFocus: true
    });
  },
  /**
   * 隐藏支付密码输入层
   */
  hidePayLayer: function(e) {
    var teacherid = this.data.teacherid;
    var order_id = this.data.order_id;
    var user_id = app.u.user_id;
    var pass = this.data.pwdVal;
    var that=this;
    this.setData({
      showPayPwdInput: false,
      payFocus: false,
      pwdVal: ''
    }, function() {
      c.ajax(
        app.url + 'xuan', {
          teacherid: teacherid,
          order_id: order_id,
          user_id: user_id,
          pass: pass
        },
        res => {
          that.setData({
            data: res.data
          })
        }
      )

    });

  },
  /**
   * 获取焦点
   */
  getFocus: function() {
    this.setData({
      payFocus: true
    });
  },
  /**
   * 输入密码监听
   */
  inputPwd: function(e) {
    this.setData({
      pwdVal: e.detail.value
    });

    if (e.detail.value.length >= 6) {
      this.hidePayLayer();
    }
  },
  taotai:function(){
    var order_id = this.data.order_id;
    wx.navigateTo({
      url: '/pages/ordertaotai/ordertaotai?order_id=' + order_id,
    })
  },
  closeorder:function(){
   var that=this;

    wx.showModal({
      title: '',
      content: '确定要关闭吗？',
      success(res) {
        if (res.confirm) {
          var order_id = that.data.order_id;
          var uid = app.u.user_id;
          c.ajax(
            app.url + 'closeOrder',
            { order_id: order_id, uid: uid },
            res => {
              var status = res.data;
              if (status == 101) {
                wx.showToast({
                  title: '禁止关闭',
                  icon: 'none',
                })
              }
              if (status == 1) {
                setTimeout(function () {
                  wx.navigateTo({
                    url: '/pages/myorderguanli/myorderguanli',
                  })
                }, 1000)
                wx.showToast({
                  title: '关闭成功',
                  icon: 'none',
                })



              }
            }
          )
        } 
      }
    })



  },
  inDetail: function (e) {
    // 商品类型：

    // 1 -> 一对一直播
    // 2 -> 单节视频
    // 3 -> 套课
    // 4 -> 套课中的视频
    // 5 -> 预约直播
    // 6 -> 一对多直播
    var gid = e.currentTarget.dataset.goodsid;
    var sql = 'w(goods_id=' + gid + ')f(type)l(1)';

    c.ajax(
      app.dbs + 'goods',
      { sql: sql },
      res => {
        var typeinfo = res.data.type;

        if (typeinfo == 2) {
          wx.navigateTo({
            url: '/pages/detailsdanke/detailsdanke?goods_id=' + gid,
          })
        } else if (typeinfo == 3) {
          wx.navigateTo({
            url: '/pages/detailtaoke/detailtaoke?goods_id=' + gid,
          })
        } else if (typeinfo == 1 || typeinfo == 6) {
          wx.navigateTo({
            url: '/pages/detailzhibo/detailzhibo?goods_id=' + gid,
          })
        }
      }
    )
  },
  natoinfo:function(e){
    var demandid = e.currentTarget.dataset.demandid;
    wx.navigateTo({
      url: '/pages/orderdescriptlist/orderdescriptlist?demandid=' + demandid,
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  clickdet:function(e){
    // 商品类型：

    // 1 -> 一对一直播
    // 2 -> 单节视频
    // 3 -> 套课
    // 4 -> 套课中的视频
    // 5 -> 预约直播
    // 6 -> 一对多直播
    var gid = e.currentTarget.dataset.goodsid;
    var sql = 'w(goods_id=' + gid + ')f(type)l(1)';
    c.ajax(
      app.dbs + 'goods', {
        sql: sql
      },
      res => {
        var typeinfo = res.data.type;
        console.log(typeinfo);
        if (typeinfo == 2) {
          wx.navigateTo({
            url: '/pages/detailsdanke/detailsdanke?goods_id=' + gid,
          })
        } else if (typeinfo == 3) {
          wx.navigateTo({
            url: '/pages/detailtaoke/detailtaoke?goods_id=' + gid,
          })
        } else if (typeinfo == 1 || typeinfo == 6) {
          wx.navigateTo({
            url: '/pages/detailzhibo/detailzhibo?goods_id=' + gid,
          })
        }
      }
    )
    
  },
  linkclick:function(){
    wx.makePhoneCall({
      phoneNumber: '4000063088',
    })
  }
})